package day1108.single;

/**
 * @author Mr.ma
 * @since 2022/11/8 19:43
 * volatile关键字：可以保证变量在多线程操作时的可见性，并保证jvm创建变量的执行顺序，防止指令重拍
 * 单例模式之饿汉式
 **/
public class VolatileTest {
    private volatile static VolatileTest volatileTest;

    private VolatileTest() {
    }

    public static VolatileTest getInstance(){
        if (volatileTest == null){
            synchronized(VolatileTest.class){
                if (volatileTest == null){
                    volatileTest = new VolatileTest();
                }
            }
        }
        return volatileTest;
    }
}